package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.char.Entity;
	import com.terrynoya.fight.combat.FightEngine;
	import com.terrynoya.fight.emuns.PlayerControl;
	import com.terrynoya.fight.evaluation.Expression;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.io.KeyValuePair;
	import com.terrynoya.fight.io.TextSection;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.stateMachine.StateMachine;
	import com.terrynoya.fight.stateMachine.controllers.attrParser.StateCtrlParserType;
	
	/**
	 * 转换状态
	 * @author yaojianzhou
	 */
	public class ChangeState extends StateController
	{
		private var _stateId:int;
		
		/**
		 * 
		 * @param stateMachine
		 * @param label
		 */
		public function ChangeState(label:String)
		{
			super(label);
		}
		
		/**
		 * 
		 * @return 
		 */
		public function get stateNumber():int
		{
			return this._stateId;
		}
		
		override protected function initAttrConvertMap():void
		{
			this.attrConvertMap.put("value",StateCtrlParserType.Expression);
		}

		/**
		 * 
		 * @param value
		 */
		public function set stateNumber(value:int):void
		{
			this._stateId = value;
		}

		override public function run(chara:Character):void
		{
			this._stateId = this.getExpression("value").excute(chara);
			chara.stateManager.changeState(this.stateNumber);
			if(this.hasExpression("ctrl"))
			{
				var ctrlExp:int = int(this.getExpression("ctrl").excute(chara));
				chara.playerControl = ctrlExp == 1 ? PlayerControl.InControl : PlayerControl.NoControl;
			}
		}
	}
}